package org.mogoo.simple.socket;

import java.awt.print.Printable;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Author: Fang
 * Date: 2012-08-21
 * Time: 15:37
 * Email: dongfang@mogoo.org
 */
public class Server
{
    public static void main(String[] args) throws Exception
    {
        ServerSocket serverSocket = new ServerSocket(8888);

/*        while(true)
        {
            Socket socket = serverSocket.accept();
            PrintStream ps = new PrintStream(socket.getOutputStream());
            ps.println("Heelo from server!");
            ps.close();
            socket.close();
        }*/
        while(true)
        {
            Socket socket = serverSocket.accept();
            Message message = new Message();
            message.setFromID(1111);
            message.setToID(2222);
            message.setMessageBody("heuifkkefxukwebf kuwebufkewbufk");
            message.setTimeStamp(new Date());
            ObjectOutputStream objos = new ObjectOutputStream(socket.getOutputStream());
            objos.writeObject(message);


            objos.close();
            socket.close();
        }


    }

}

class Message implements Serializable
{
    private int fromID;
    private int toID;
    private String messageBody;

    public int getFromID()
    {
        return fromID;
    }

    public void setFromID(int fromID)
    {
        this.fromID = fromID;
    }

    public int getToID()
    {
        return toID;
    }

    public void setToID(int toID)
    {
        this.toID = toID;
    }

    public String getMessageBody()
    {
        return messageBody;
    }

    public void setMessageBody(String messageBody)
    {
        this.messageBody = messageBody;
    }

    public Date getTimeStamp()
    {
        return timeStamp;
    }

    public void setTimeStamp(Date timeStamp)
    {
        this.timeStamp = timeStamp;
    }

    private Date timeStamp;

}



